#include <cstdio>

const int MAX = 1000;

struct student {
    long long id;
    int seatId;
}S[MAX+10];

int main() {
    int n, m, seatId, exam;
    long long id;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lld%d%d", &id, &exam, &seatId);
        S[exam].id = id;
        S[exam].seatId = seatId;
    }
    scanf("%d", &m);
    for (int i = 0; i < m; i++) {
        scanf("%d", &exam);
        printf("%lld %d\n", S[exam].id, S[exam].seatId);
    }

    return 0;
}